
<template>
  <LsdDialog :dialogConfig="dialogConfig" @handleBtn="handleBtn" @close="handleClose">
    <!-- <el-dialog title="响应命令单" :visible="dialogVisible" width="60%" :before-close="handleClose"> -->
    <LsdDialogTitle slot="dialog" :titleConfig="titleConfig" :activeNames="activeNames">
      <DialogForm @change="getJudgeData" ref="formComponent" slot="slot1" :formConfig="formConfig" />
      <DialogForm ref="formComponent1" slot="slot1" :formConfig="formConfig1" />
      <div slot="slot2">
        <LsdTable slot="cxyq" :paginationAtrrs="paginationAtrrs" :compRef="tableList.compRef" ref="gjxm" :columns="tableList.columns" :tableData="tableList.tableData" :tableAttr="tableList.tableAttr" :isSequenceFlag="tableList.isSequenceFlag" @onActionClick="onActionClick1111" />
      </div>
      <div slot="slot3">
        <DialogForm ref="formComponent2" :formConfig="formConfig2" />
      </div>
      <div slot="slot4">
        <DialogForm ref="formComponent3" :formConfig="formConfig3" />
      </div>
      <div slot="slot5">
        <DialogForm ref="formComponent4" :formConfig="formConfig4" />
      </div>
    </LsdDialogTitle>
    <!-- </el-dialog> -->
  </LsdDialog>
</template>

<script>
import {
  getinfo,
  editlist,
  xymldFeedbackSave,
  getjudgelist,
  getjudgeinfo,
  xymldFeedbacksubmit
} from "@/api/EmergencyDisposal/xymld";
export default {
  name: "EmergencyResponseAdd",
  components: {},
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    type: {
      type: Object,
      default: function () {
        return {};
      }
    },
    id: {
      type: [String, Number],
      default: function () {
        return "";
      }
    }
  },
  data() {
    return {
      // 弹窗表单信息
      formConfig4: {
        disabled: true,
        formData: [
          {
            type: "input",
            label: "审批意见",
            prop: "emergencyEvent",
            class: "sjgy",
            lableWidth: "100px",
            option: []
          },
          {
            type: "input",
            label: "审批人",
            prop: "eventName",
            class: "third",
            disabled: true,
            lableWidth: "120px"
          },
          {
            type: "input",
            label: "单位及部门",
            prop: "eventLvName",
            class: "third",
            disabled: true,
            lableWidth: "120px"
          },
          {
            type: "input",
            label: "审批时间",
            prop: "effectRange",
            class: "third",
            disabled: true,
            lableWidth: "120px"
          }

        ]
      },
      formConfig3: {
        disabled: true,
        formData: [
          // {
          //   type: "select",
          //   label: "应急事件",
          //   prop: "emergencyEvent",
          //   class: "sjgy",
          //   lableWidth: "100px",
          //   option: []
          // },
          {
            type: "input",
            label: "填报人",
            prop: "creator",
            class: "third",
            lableWidth: "120px"
          },
          {
            type: "input",
            label: "单位及部门",
            prop: "createDeptName",
            class: "third",
            lableWidth: "120px"
          },
          {
            type: "input",
            label: "填报时间",
            prop: "createTime",
            class: "third",
            lableWidth: "120px"
          }
        ]
      },
      // 弹窗表单信息
      formConfig2: {
        formData: [
          {
            type: "select",
            label: "主送单位",
            prop: "mainUnitId",
            dic: "mainUnitId",
            class: "sjgy",
            lableWidth: "120px",
            isShow: true,
            option: [
              {
                value: "1",
                label: "国网随电公司"
              },
              {
                value: "2",
                label: "国网随州供电公司公司"
              },
              {
                value: "3",
                label: "国网公司"
              }
            ]
          },
          {
            type: "select",
            label: "响应部门",
            prop: "responseDeptId",
            dic: "dic_xybm",
            class: "sjgy",
            lableWidth: "120px",
            isShow: true,
            option: [
              {
                value: "1",
                label: "办公室"
              },
              {
                value: "2",
                label: "设备部"
              },
              {
                value: "3",
                label: "安监部"
              }
            ]
          },
          {
            type: "select",
            label: "联系人",
            prop: "linkman",
            dic: "dic_lxr",
            class: "sjgy",
            lableWidth: "120px",
            isShow: true,
            option: [
              {
                label: "专项应急办: 俞斌137888802",
                value: "专项应急办: 俞斌137888802"
              },
              {
                label: "专项应急办: 付婧1384665802",
                value: "专项应急办: 付婧1384665802"
              },
              {
                label: "专项应急办: 赵爱国1569858802",
                value: "专项应急办: 赵爱国1569858802"
              }
            ]
          },
          {
            type: "select",
            label: "抄报",
            prop: "outTheNewspaper",
            dic: "dic_cb",
            class: "half",
            lableWidth: "120px",
            isShow: true,
            option: [
              {
                value: "1",
                label: "湖北省应急厅"
              },
              {
                value: "2",
                label: "湖北省能源厅"
              }
            ]
          },
          {
            type: "select",
            label: "抄送",
            prop: "sendDuplicate",
            dic: "dic_cs",
            class: "half",
            lableWidth: "120px",
            isShow: true,
            option: [
              {
                value: "1",
                label: "国网湖北省电力有限公司"
              },
              {
                value: "2",
                label: "国网湖北省电力有限公司安监部"
              }
            ]
          }
        ],
        rules: {
          mainUnitId: [
            { required: true, message: "请选择主送单位", trigger: "change" }
          ],
          responseDeptId: [
            { required: true, message: "请选择响应部门", trigger: "change" }
          ],
          linkman: [
            { required: true, message: "请选择联系人", trigger: "change" }
          ],
          outTheNewspaper: [
            { required: true, message: "请选择抄报", trigger: "change" }
          ],
          sendDuplicate: [
            { required: true, message: "请选择抄送", trigger: "change" }
          ]
        }
      },
      paginationAtrrs: {
        total: 0,
        layout: "total, sizes, prev, pager, next, jumper",
        "current-page": 1,
        "page-size": 10,
        "page-sizes": [10, 20, 30, 40, 50, 100]
      },
      tableList: {
        isSelectFlag: true,
        compRef: "cxyq",
        isSequenceFlag: true,
        isShowPage: true,
        resetFlag: true,
        loading: false,
        title: "响应命令单列表",
        actions: [],
        tableData: [
          {
            measureRequire: "",
            unitDeptId: ""
          }
        ],
        columns: [
          {
            prop: "measureRequire",
            label: "有关措施要求",
            align: "center",
            "min-width": "200px",
            render: (h, { row }) => {
              return (
                <div class='peizhi'>
                  <LsdForm
                    compData={{
                      elType: "input",
                      id: "measureRequire",
                      label: "有关措施要求",
                      attrs: {
                        // disabled:
                        //   _this.operat === "review" ||
                        //   !["task999"].includes(_this.$route.query.task) ||
                        //   ["task2", "task3"].includes(
                        //     _this.$route.query.returnFlow
                        //   ),
                        disabled: false,
                        value: "",
                        placeholder: "请输入",
                        min: 0,
                        type: "text"
                      }
                    }}
                    form={row}
                    {...{
                      on: {}
                    }}
                  ></LsdForm>
                </div>
              );
            }
          },
          {
            prop: "unitDeptId",
            label: "部门/单位",
            align: "center",
            "min-width": "70px",
            render: (h, { row }) => {
              return (
                <div class='peizhi'>
                  <LsdForm
                    compData={{
                      elType: "select",
                      id: "unitDeptId",
                      label: "部门/单位",
                      // dic: "dic_zrbm",
                      attrs: {
                        value: "",
                        clearable: true,
                        filterable: true,
                        disabled: false,
                        multiple: false,
                        "collapse-tags": true
                      },
                      options: this.dwjbmlist
                      // [
                      // {
                      //   label: "111",
                      //   value: 1
                      // },
                      // {
                      //   label: "222",
                      //   value: 2
                      // },
                      // {
                      //   label: "333",
                      //   value: 3
                      // }
                      // ]
                    }}
                    form={row}
                    {...{
                      on: {}
                    }}
                  ></LsdForm>
                </div>
              );
            }
          },
          {
            prop: "cz",
            label: "操作",
            align: "center",
            fixed: "right",
            "min-width": "40px",
            render: (h, scope) => {
              // console.log(scope,">>>>>>>>>>>>>>>>>>row");
              return (
                <div>
                  {
                    scope.$index === this.tableList.tableData.length - 1 && (

                      <el-button
                        {...{
                          class: {},
                          style: {},
                          attrs: {
                            type: "text",
                            icon: "el-icon-plus",
                            size: "small"
                          },
                          on: {
                            click: (scope) => {
                              this.tableList.tableData.push({
                                measureRequire: "",
                                unitDeptId: ""
                              });
                            }
                          }
                        }}
                      />
                    )
                  }
                  <el-button
                    {...{
                      class: {},
                      style: {},
                      attrs: {
                        type: "text",
                        icon: "el-icon-minus",
                        size: "small"
                      },
                      on: {
                        click: () => {
                          console.log(scope);
                          if (scope.$index < 1) {
                            return;
                          }
                          this.tableList.tableData.splice(scope.$index, 1);
                        }
                      }
                    }}
                  />
                </div>
              );
            }
          }
        ],
        tableAttr: {
          "max-height": "470px",
          height: "470px",
          stripe: false,
          border: true,
          fit: true,
          "show-header": true,
          "highlight-current-row": true,
          "cell-style": {
            "font-size": "16px"
          },
          "header-cell-style": {
            "text-align": "center",
            "background-color": "#B1C8F9",
            border: "1px solid #ccc",
            "font-size": "16px"
          }
        }
      },
      // 弹窗表单信息
      formConfig: {
        formData: [
          {
            type: "select",
            label: "响应研判单",
            prop: "judgeId",
            dic: "judgeId",
            class: "sjgy",
            lableWidth: "120px",
            isShow: true,
            option: []
          }
        ],
        rules: {
          judgeId: [
            { required: true, message: "请选择响应研判单", trigger: "change" }
          ]
        }
      },
      // 弹窗表单信息
      formConfig1: {
        formData: [
          {
            type: "input",
            label: "响应命令单",
            prop: "responseName",
            class: "sjgy",
            isDisabled: true,
            lableWidth: "120px"
          },
          {
            type: "input",
            label: "事件类别",
            prop: "eventName",
            class: "half",
            isDisabled: true,
            lableWidth: "100px"
          },
          {
            type: "input",
            label: "影响范围",
            prop: "effectRange",
            class: "half",
            isDisabled: true,
            lableWidth: "120px"
          },
          {
            type: "input",
            label: "响应级别",
            prop: "responseLvName",
            class: "half",
            isDisabled: true,
            lableWidth: "100px"
          },
          {
            type: "dataPicker",
            label: "影响时间",
            prop: "effectTime",
            class: "half",
            dateType: "datetime",
            lableWidth: "120px"
          },
          {
            type: "textarea",
            label: "事件概要",
            prop: "incidentOutline",
            class: "sjgy",
            isDisabled: true,
            lableWidth: "100px"
          }
        ],
        rules: {
          effectTime: [
            { required: true, message: "请选择影响时间", trigger: "change" }
          ]
        }
      },
      // 折叠面板信息
      titleConfig: [
        {
          title: "基本信息",
          name: "1",
          slot: "slot1"
        },
        {
          title: "措施要求",
          name: "2",
          slot: "slot2"
        },
        {
          title: "响应信息",
          name: "3",
          slot: "slot3"
        },
        {
          title: "填报信息",
          name: "4",
          slot: "slot4"
        },
        {
          title: "审批信息",
          name: "5",
          slot: "slot5"
        }
      ],
      // 弹窗信息
      dialogConfig: {
        title: "响应命令单",
        isShow: false, // 弹窗显示隐藏
        btnList: [
          {
            name: "提交",
            id: "Submit", // 事件名
            type: "primary",
            size: "small"
          },
          {
            name: "保存",
            id: "save",
            size: "small"
          },
          {
            name: "取消",
            id: "cancel",
            size: "small"
          }
        ]
      },
      dwjbmlist: [
        {
          value: "1",
          label: "办公室"
        },
        {
          value: "2",
          label: "设备部"
        },
        {
          value: "3",
          label: "安监部"
        }
      ],
      activeNames: ["1", "2", "3", "4", "5"], // 折叠面板默认展开列
      cslist: [],
      cblist: [],
      lxrlist: [],
      xybmlist: [],
      zsdwlist: [],
      btnList: [
        {
          name: "提交",
          id: "Submit", // 事件名
          type: "primary",
          size: "small"
        },
        {
          name: "保存",
          id: "save",
          size: "small"
        },
        {
          name: "取消",
          id: "cancel",
          size: "small"
        }
      ],
      btnList1: [
        {
          name: "保存",
          id: "save",
          type: "primary",
          size: "small"
        },
        {
          name: "取消",
          id: "cancel",
          size: "small"
        }
      ]
    };
  },
  watch: {
    dialogVisible: {
      handler(val) {
        if (val) {
          if (this.type.code === "edit" || this.type.code === "adjustment") {
            this.getinfo();
          }
          this.dialogConfig.isShow = true;
          this.getInputVal();
          if (this.type.code === "adjustment") {
            this.dialogConfig.btnList = this.btnList1;
          } else {
            this.dialogConfig.btnList = this.btnList;
          }
        } else {
          this.dialogConfig.isShow = false;
          this.$emit("list");
          this.cancel();
        }
      },
      deep: true,
      immediate: true
    }
  },
  created() { },
  mounted() { },
  methods: {
    handleBtn(item) {
      this[item.id]();
    },
    onActionClick1111() { },
    async getJudgeData() {
      if (this.$refs.formComponent.form.judgeId) {
        const res = await getjudgeinfo({ id: this.$refs.formComponent.form.judgeId });
        this.$set(this.$refs.formComponent1, "form", res);
        this.$set(this.$refs.formComponent3, "form", res);
        this.$set(this.$refs.formComponent4, "form", res);
      } else {
        this.data = {};
      }
    },
    // 获取下拉框数据
    getInputVal() {
      this.formConfig.formData.forEach((item) => {
        if (item.dic) {
          getjudgelist().then(res => {
            const option = res.map((item) => {
              return {
                label: item.judgeName,
                value: item.id
              };
            });
            item.option = option;
          });
        }
      });
    },
    async save() {
      if (this.type.code === "add") {
        this.$refs.formComponent.isValidate();
        this.$refs.formComponent1.isValidate();
        this.$refs.formComponent2.isValidate();
        const flag = this.$refs.formComponent.flag;
        const flag1 = this.$refs.formComponent1.flag;
        const flag2 = this.$refs.formComponent2.flag;
        if (flag && flag1 && flag2) {
          const parmas = {
            creator: "朱",
            modifier: "朱",
            judgeId: this.$refs.formComponent.form.judgeId,
            responseName: this.$refs.formComponent1.form.responseName,
            effectTime: this.$refs.formComponent1.form.effectTime + "至 响应终止",
            emergencyMeasureSaveDto: this.tableList.tableData,
            mainUnitId: this.$refs.formComponent2.form.mainUnitId,
            responseDeptId: this.$refs.formComponent2.form.responseDeptId,
            linkman: this.$refs.formComponent2.form.linkman,
            outTheNewspaper: this.$refs.formComponent2.form.outTheNewspaper,
            sendDuplicate: this.$refs.formComponent2.form.sendDuplicate,
            emergencyEventIds: this.$refs.formComponent1.form.emergencyEventIds
          };
          await xymldFeedbackSave(parmas);
          this.$message({
            message: "保存成功",
            type: "success"
          });
          this.$emit("update:dialogVisible", false);
        }

      } else if (this.type.code === "edit" || this.type.code === "adjustment") {
        this.$refs.formComponent.isValidate();
        this.$refs.formComponent1.isValidate();
        this.$refs.formComponent2.isValidate();
        const flag = this.$refs.formComponent.flag;
        const flag1 = this.$refs.formComponent1.flag;
        const flag2 = this.$refs.formComponent2.flag;
        if (flag && flag1 && flag2) {
          const parmas = {
            creator: "朱",
            modifier: "朱",
            judgeId: this.$refs.formComponent.form.judgeId,
            responseName: this.$refs.formComponent1.form.responseName,
            effectTime: this.$refs.formComponent1.form.effectTime + "至 响应终止",
            emergencyMeasureUpdDtos: this.tableList.tableData,
            mainUnitId: this.$refs.formComponent2.form.mainUnitId,
            responseDeptId: this.$refs.formComponent2.form.responseDeptId,
            linkman: this.$refs.formComponent2.form.linkman,
            outTheNewspaper: this.$refs.formComponent2.form.outTheNewspaper,
            sendDuplicate: this.$refs.formComponent2.form.sendDuplicate,
            emergencyEventIds: this.$refs.formComponent1.form.emergencyEventIds,
            id: this.id
          };
          editlist(parmas);
          this.$message({
            message: "修改成功",
            type: "success"
          });
          this.$emit("update:dialogVisible", false);
        }
      }
    },
    async getinfo() {
      const res = await getinfo({ id: this.id });
      this.$set(this.$refs.formComponent, "form", res);
      this.$set(this.$refs.formComponent1, "form", res);
      this.$set(this.$refs.formComponent2, "form", res);
      this.tableList.tableData = res.emergencyMeasureListVos;
      this.$set(this.$refs.formComponent3, "form", res);
      this.$set(this.$refs.formComponent4, "form", res);
    },
    async Submit() {
      if (this.type.code === "add") {
        this.$refs.formComponent.isValidate();
        this.$refs.formComponent1.isValidate();
        this.$refs.formComponent2.isValidate();
        const flag = this.$refs.formComponent.flag;
        const flag1 = this.$refs.formComponent1.flag;
        const flag2 = this.$refs.formComponent2.flag;
        if (flag && flag1 && flag2) {
          const parmas = {
            creator: "朱",
            modifier: "朱",
            judgeId: this.$refs.formComponent.form.judgeId,
            responseName: this.$refs.formComponent1.form.responseName,
            effectTime: this.$refs.formComponent1.form.effectTime,
            emergencyMeasureUpdDtos: this.tableList.tableData,
            mainUnitId: this.$refs.formComponent2.form.mainUnitId,
            responseDeptId: this.$refs.formComponent2.form.responseDeptId,
            linkman: this.$refs.formComponent2.form.linkman,
            outTheNewspaper: this.$refs.formComponent2.form.outTheNewspaper,
            sendDuplicate: this.$refs.formComponent2.form.sendDuplicate,
            emergencyEventIds: this.$refs.formComponent1.form.emergencyEventIds
          };
          await xymldFeedbacksubmit(parmas);
          this.$message({
            message: "提交成功",
            type: "success"
          });
          this.$emit("update:dialogVisible", false);
        }

      } else if (this.type.code === "edit") {
        this.$refs.formComponent.isValidate();
        this.$refs.formComponent1.isValidate();
        this.$refs.formComponent2.isValidate();
        const flag = this.$refs.formComponent.flag;
        const flag1 = this.$refs.formComponent1.flag;
        const flag2 = this.$refs.formComponent2.flag;
        if (flag && flag1 && flag2) {
          const parmas = {
            creator: "朱",
            modifier: "朱",
            judgeId: this.$refs.formComponent.form.judgeId,
            responseName: this.$refs.formComponent1.form.responseName,
            effectTime: this.$refs.formComponent1.form.effectTime,
            emergencyMeasureUpdDtos: this.tableList.tableData,
            mainUnitId: this.$refs.formComponent2.form.mainUnitId,
            responseDeptId: this.$refs.formComponent2.form.responseDeptId,
            linkman: this.$refs.formComponent2.form.linkman,
            outTheNewspaper: this.$refs.formComponent2.form.outTheNewspaper,
            sendDuplicate: this.$refs.formComponent2.form.sendDuplicate,
            id: this.id,
            emergencyEventIds: this.$refs.formComponent1.form.emergencyEventIds
          };
          await xymldFeedbacksubmit(parmas);
          this.$message({
            message: "提交成功",
            type: "success"
          });
          this.$emit("update:dialogVisible", false);
        }

      }
    },
    handleClose() {
      this.$emit("update:dialogVisible", false);
    },
    cancel() {
      this.$refs.formComponent.form = this.$refs.formComponent.$options.data().form;
      this.$refs.formComponent1.form = this.$refs.formComponent1.$options.data().form;
      this.$refs.formComponent2.form = this.$refs.formComponent2.$options.data().form;
      this.$refs.formComponent3.form = this.$refs.formComponent3.$options.data().form;
      this.$refs.formComponent4.form = this.$refs.formComponent4.$options.data().form;
      this.$nextTick(() => {
        this.$refs.formComponent.$refs.formInlines.clearValidate();
        this.$refs.formComponent1.$refs.formInlines.clearValidate();
        this.$refs.formComponent2.$refs.formInlines.clearValidate();
        this.$refs.formComponent3.$refs.formInlines.clearValidate();
        this.$refs.formComponent4.$refs.formInlines.clearValidate();
      });
      this.$emit("update:dialogVisible", false);
    }
  }
};
</script>

<style scoped lang="less">
</style>
